package edu.neu.cs6515.hci.test.integration;

import java.io.File;
import java.io.IOException;
import java.util.Iterator;

import javax.swing.JFrame;
import javax.xml.bind.JAXBException;

import org.apache.commons.io.FileUtils;

import edu.neu.cs6515.hci.HCIPanel;
import edu.neu.cs6515.hci.HCIStrategy;
import edu.neu.cs6515.player.strategy.StrategyException;
import edu.neu.cs6515.test.IterateXMLFileAndTest;
import edu.neu.cs6515.xml.Placement;
import edu.neu.cs6515.xml.Player;
import edu.neu.cs6515.xml.XMLPlayerUnmarshaller;

/**
 * test class that read input xml files for HCIStrategy
 */
public final class NotJUnitTestInputFileForHCI {

    /**
     * C'tor to avoid NotJUnitTestInputFileForHCI to be instantiated
     */
    private NotJUnitTestInputFileForHCI() {
    }

    private static final String FOLDER = "./xml-testdata/W10-xml-input-files/";

    /**
     * iterate input files in FOLDER, lauch HCIStrategies
     * 
     * @param args
     *            commandline arguments
     * @throws IOException
     * @throws JAXBException
     */
    public static void main(final String[] args) throws IOException,
            JAXBException {
        final Iterator<File> iterateFiles = FileUtils.iterateFiles(new File(
                FOLDER), new String[] { IterateXMLFileAndTest.FILE_SUFFIX }, false);
        while (iterateFiles.hasNext()) {
            final String playerDefinition = FileUtils
                    .readFileToString(iterateFiles.next());
            Player player = new XMLPlayerUnmarshaller()
                    .unmarshall(playerDefinition);

            HCIPanel hciPanel = new HCIPanel(player.getInterval());
            JFrame frame = new JFrame();
            frame.setContentPane(hciPanel);
            frame.setSize(500, 600);
            frame.setLocation(100, 100);
            frame.setVisible(true);

            HCIStrategy hciStrategy = new HCIStrategy(player.getInterval(), hciPanel);
            try {
                Placement userPlacement = hciStrategy.getNextMove(
                        player.getTile(), player.getBoard().getPlayers(),
                        player.getBoard().getPlacement(), player.getScore());
                System.out.println("placement" + userPlacement.toXMLString());
            } catch (StrategyException e) {
                System.out.println("StrategyException:" + e.getMessage());
            }
            System.out.println();
        }
    }
}
